import { observable, computed, action } from 'mobx';
import axios from 'axios';
class User {    
    @observable loginStatus = false;
    @observable loginInfo = null;
    @action login(phone, password) {        
        return new Promise((resolve, reject) => {
            axios.post('http://proxy.jinpu.8raw.com/By_UserAccount_loginByMobile', {
                    mobile: phone,
                    password: password,        
                    role: '',    
                    code: 'itboye',
                    service_type: 'By_UserAccount_loginByMobile',
                    service_version: '103',
                    notify_id: 0
                })
                .then(response => {                    
                    console.log('111');       
                    if(response.data.code == 0) this.loginStatus = true;    
                    this.loginInfo = response.data;  
                    resolve(response.data);                    
                })
        })
        
        // let isLogin = axios.post('http://proxy.jinpu.8raw.com/By_UserAccount_loginByMobile', {
        //     mobile: phone,
        //     password: password,        
        //     role: '',    
        //     code: 'itboye',
        //     service_type: 'By_UserAccount_loginByMobile',
        //     service_version: '102',
        //     notify_id: 0
        // }).then(result => {            
            
        // });
    } 
    @action async checkLogin() {
        // const result = await ApiHelper.requestPost(checkLogin);
        // if (result.status && result.info.user) {
        //     this.info = result.info.user;
        //     return true;
        // } else {
        //     this.info = null;
        //     return false;
        // }        
        if (this.loginStatus) {
            return true;
        } else {
            return false;
        }                           
    }
    @action async logout() {
        // const result = await ApiHelper.requestPost(logOut);
        // if (result.status) {
        //     message.success(result.info, 1.5);
        // }      
    }
}

export default new User;